<?php
/**
 * 系统设置
 * @author 齐迹  email:smpss2012@gmail.com
 *
 */
class c_cangku extends base_c
{
    public function __construct($inPath)
    {
        parent::__construct();
        if (self::isLogin() === false) {
            $this->ShowMsg("请先登录！", $this->createUrl("/main/index"));
        }
        if (self::checkRights($inPath) === false) {
            //$this->ShowMsg("您无权操作！",$this->createUrl("/system/index"));
        }
        $this->params['inpath'] = $inPath;
        $this->params['head_title'] = "仓库-" . $this->params['head_title'];
    }
    public function pageindex($inPath)
    {
        $url = $this->getUrlParams($inPath);
        $cangkuObj = new m_cangku();
        $this->params['items'] = $cangkuObj->select()->items;
        return $this->render('cangku/index.html', $this->params);
    }

    public function pageadd($inPath)
    {
        $url = $this->getUrlParams($inPath);
        $id = (int) $url['id'] > 0 ? (int) $url['id'] : (int) $_POST['id'];
        $cangkuObj = new m_cangku($id);

        if (!$_POST['cangku_name']) {
            if ($id) {
                $this->params['cangku'] = $cangkuObj->get();
            }
            return $this->render('cangku/add.html', $this->params);
        } else {
            $item = array();
            $item['cangku_name'] = base_Utils::shtmlspecialchars($_POST['cangku_name']);
            if ($item['cangku_name']) {
                $cangkuObj = new m_cangku();
                $res = $cangkuObj->selectOne("cangku_name='{$item['cangku_name']}' and id!={$id}", 'id');
                if ($res) {
                    $this->ShowMsg('仓库名称已经存在！');
                }
                if ($id) {
                    $item['id'] = $id;
                }
                $rs = $cangkuObj->create($item);
                if ($rs) {
                    $this->ShowMsg('添加成功', $this->createUrl('/cangku/index'));
                } else {
                    $this->ShowMsg('添加失败，请重试！错误原因：' . $cangkuObj->getError());
                }
            }
            $this->ShowMsg('仓库名称不能够为空！');
        }
    }
}
